package com.blockmeta.bbs.businesslibrary.flutter;

import android.util.Log;


import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StringCodec;

public class BasicMessageFlutterPlugins {
    private static final String CHANNEL_NAME = "basic_channel";

    static BasicMessageChannel<String> basicMessageChannel;
    public static void register(BinaryMessenger messenger) {
        basicMessageChannel = new BasicMessageChannel(messenger, CHANNEL_NAME, StringCodec.INSTANCE);
        basicMessageChannel.setMessageHandler((message, reply) -> {
            Log.d("tingflutter", String.valueOf(message));
            //通过delege获取到数据返回
            reply.reply("收到flutter message");
        });
    }

    public static void send(MessageEvent message){
        Log.d("flutterting", "send to flutter" + message.toJson());
        basicMessageChannel.send(message.toJson()
                , reply -> Log.d("tingflutter", reply.toString()));
    }
}
